#include "LuaString.h"
#include "LuaObjectImpl.h"

LuaString::LuaString()
{

}

LuaString::LuaString(const LuaObject& rfs)
	:LuaObject(rfs)
{
}

LuaString::~LuaString()
{

}

bool LuaString::isValid()
{
	return getType() == LUA_TSTRING;
}

const char* LuaString::c_str() const
{
	return toString();
}

bool LuaString::set(const char* str)
{
	if (!m_ptr || !str)
		return false;
	lua_State* L=m_ptr->getLuaState();
	lua_pushstring(L,str);
	lua_replace(L, m_ptr->getIndex());
	return true;
}

bool LuaString::set(const char* str, size_t len)
{
	if (!m_ptr || !str)
		return false;
	lua_State* L = m_ptr->getLuaState();
	lua_pushlstring(L, str,len);
	lua_replace(L, m_ptr->getIndex());
	return true;
}

size_t LuaString::length() {
	return objLen();
}

LuaString::operator const char*()
{
	return toString();
}

